<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            margin: 100px auto;
            width: 200px;
            height: 200px;
            background-color: pink;
        }
    </style>
</head>

<body>
    <div>
        1
    </div>
    <script>
        var div = document.querySelector('div');
        div.addEventListener('mousemove', function(e) {
            console.log(e.pageX);
            console.log(e.pageY);
            console.log(this.offsetLeft);
            console.log(this.offsetTop);
            var x = e.pageX - this.offsetLeft;
            var y = e.pageY - this.offsetTop;
            div.innerHTML = '鼠标在盒子中的坐标分别为' + 'x ' + x + ' y ' + y;
        })
    </script>
</body>

</html>